import Vue from 'vue'
import VueRouter from 'vue-router'

//主页
import Main from '@/components/Main';

//院校信息
import Colleges from '@/components/pages/colleges/colleges_main'
import all_colleges from "@/components/pages/colleges/sort/all_colleges";
import One_Colleges from "@/components/pages/colleges/one_college"
import college_grades from "@/components/pages/colleges/college_grades";
import academic_grades from "@/components/pages/colleges/grades_sort/academic_grades";
import profession_grades from "@/components/pages/colleges/grades_sort/profession_grades";

//交流讨论社区
import experience_discussion from "@/components/pages/discussion/sort/experience_discussion";
import life_discussion from "@/components/pages/discussion/sort/life_discussion";
import other_discussion from "@/components/pages/discussion/sort/other_discussion";
import question_discussion from "@/components/pages/discussion/sort/question_discussion"
import all_discussion from "@/components/pages/discussion/sort/all_discussion"
import one_post from "@/components/pages/discussion/one_post";
import one_post_main from "@/components/pages/discussion/one_post_main";
import discussion_frame from "@/components/pages/discussion/discussion_frame";


//闲置转卖
import Score from '@/components/pages/score/score_main'
import Resale from '@/components/pages/resale/resale_main'
import all_resale from "@/components/pages/resale/sort/all_resale";

//考研资讯
import Information from '@/components/pages/information/Information_main'
import KaoYan_Frame from "@/components/pages/information/KaoYan_Frame";
import KaoYan_Info from "@/components/pages/information/Sort/KaoYan_Info";
import Daily_Info from "@/components/pages/information/Sort/Daily_Info";
import Recommend_Info from "@/components/pages/information/Sort/Recommend_Info";
import ZhaoShen_Info from "@/components/pages/information/Sort/ZhaoShen_Info";
import Other_Info from "@/components/pages/information/Sort/Other_Info";
import One_Info from "@/components/pages/information/one_info";


//登陆注册
import Gegister from "@/components/register";


//个人中心
import Personal from '@/components/pages/Personal/personal_main'
import person_info from "@/components/pages/Personal/person_info";
import person_attention from "@/components/pages/Personal/person_center/person_attention";
import person_collect from "@/components/pages/Personal/person_center/person_collect";
import person_comment from "@/components/pages/Personal/person_center/person_comment";
import person_post from "@/components/pages/Personal/person_center/person_post";
import person_note from "@/components/pages/Personal/person_center/person_note";
import person_idle from "@/components/pages/Personal/person_center/person_idle";
import one_note from "@/components/pages/Personal/one/one_note";
import one_mypost from "@/components/pages/Personal/one/one_mypost";
import one_myidle from "@/components/pages/Personal/one/one_myidle";
import my_post_comment from "@/components/pages/Personal/person_center/comment/my_post_comment";
import my_idle_comment from "@/components/pages/Personal/person_center/comment/my_idle_comment";


import person_basic from "@/components/pages/Personal/person_info/person_basic";
import person_identity from "@/components/pages/Personal/person_info/person_identity";
import person_account from "@/components/pages/Personal/person_info/person_account";
import discussion_main from "@/components/pages/discussion/discussion_main";

//其他用户个人中心
import user_main from "@/components/pages/Find_User_main/user_main";
import user_idle from "@/components/pages/Find_User_main/user_idle";
import user_note from "@/components/pages/Find_User_main/user_note";
import user_post from "@/components/pages/Find_User_main/user_post";
import user_one_note from "@/components/pages/Find_User_main/user_one_note";

//交易聊天窗体
import idle_talks from "@/components/pages/Talks/idle_talks";

//我的交易表格
import deal_main from "@/components/pages/Deal/deal_main";
import my_buy_deals from "@/components/pages/Deal/sort/my_buy_deals";
import my_sale_deals from "@/components/pages/Deal/sort/my_sale_deals";

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Main',
    component: Main,
  },
  // 交易聊天窗
  // {
  //   path: '/Idle_Talks',
  //   name: 'Idle_Talks',
  //   component: idle_talks,
  // },
  //我的交易表格
  {
    path: '/Deal_Main',
    name: 'Deal_Main',
    component: deal_main,
    children: [
      {
        path: '/Deal_Main/My_Sale_Deals',
        name: 'My_Sale_Deals',
        component: my_sale_deals,
      },
      {
        path: '/Deal_Main/My_Buy_Deals',
        name: 'My_Buy_Deals',
        component: my_buy_deals,
      },

    ]
  },
  //  考研资讯
  {
    path: '/KaoYan_Frame',
    name:'KaoYan_Frame',
    component: KaoYan_Frame,
    children: [
      {
        path: '/KaoYan_Frame/Information',
        name: 'Information',
        component: Information,
      },
      {
        path: '/KaoYan_Frame/KaoYan_Info',
        name:'KaoYan_Info',
        component: KaoYan_Info
      },
      {
        path: '/KaoYan_Frame/Daily_Info',
        name:'Daily_Info',
        component: Daily_Info
      },
      {
        path: '/KaoYan_Frame/Recommend_Info',
        name:'Recommend_Info',
        component: Recommend_Info
      },
      {
        path: '/KaoYan_Frame/ZhaoShen_Info',
        name:'ZhaoShen_Info',
        component: ZhaoShen_Info
      },
      {
        path: '/KaoYan_Frame/Other_Info',
        name:'Other_Info',
        component: Other_Info
      },
      {
        path: '/KaoYan_Frame/One_Info',
        name:'One_Info',
        component: One_Info
      },
    ]
  },
  //  院校信息
  {
    path: '/Colleges',
    name: 'Colleges',
    component: Colleges,
    children: [
      {
        path:'/Colleges/All_Colleges',
        component: all_colleges
      }
    ]
  },
  //  考研国家线信息
  {
    path: '/College_Grades',
    name: 'College_Grades',
    component: college_grades,
    children: [
      {
        path: '/College_Grades/Academic_Grades',
        name:'Academic_Grades',
        component: academic_grades,
      },
      {
        path: '/College_Grades/Profession_Grades',
        name:'Profession_Grades',
        component: profession_grades,
      },

    ]
  },
  {
    path: '/One_Colleges',
    name: 'One_Colleges',
    component: One_Colleges
  },
  //交流讨论社区
  {
    path: '/Discussion_Frame',
    name: 'Discussion_Frame',
    component: discussion_frame,
    children: [
      {
        path: '/Discussion_Frame/Discussion_Main',
        name:'Discussion_Main',
        component: discussion_main,
        children:[
          {
            path: '/Discussion_Frame/Discussion_Main/All_Discussion',
            name:'All_Discussion',
            component: all_discussion
          },
          {
            path: '/Discussion_Frame/Discussion_Main/Experience_Discussion',
            name:'Experience_Discussion',
            component: experience_discussion
          },
          {
            path: '/Discussion_Frame/Discussion_Main/Life_Discussion',
            name:'Life_Discussion',
            component: life_discussion
          },
          {
            path: '/Discussion_Frame/Discussion_Main/Question_Discussion',
            name:'Question_Discussion',
            component: question_discussion
          },
          {
            path: '/Discussion_Frame/Discussion_Main/Other_Discussion',
            name:'Other_Discussion',
            component: other_discussion
          },
        ]
      },
      {
        path: '/Discussion_Frame/One_Post_Main',
        name:'One_Post_Main',
        component: one_post_main,
        children: [
          {
            path: '/Discussion_Frame/One_Post_Main/One_Post',
            name:'One_Post',
            component: one_post
          },
        ]
      },


    ]
  },
  //  个人中心
  {
    path: '/Personal',
    name: 'Personal',
    component: Personal,
    children: [
      {
        path: '/Personal/Person_Attention',
        name:'Person_Attention',
        component: person_attention
      },
      {
        path: '/Personal/Person_Collect',
        name:'Person_Collect',
        component: person_collect
      },
      {
        path: '/Personal/Person_Comment',
        name:'Person_Comment',
        component: person_comment,
        children: [
          {
            path: '/Personal/Person_Comment/My_Post_Comment',
            component: my_post_comment
          },
          {
            path: '/Personal/Person_Comment/My_Idle_Comment',
            component: my_idle_comment
          }
        ]
      },
      {
        path: '/Personal/Person_Post',
        name:'Person_Post',
        component: person_post
      },
      {
        path: '/Personal/Person_Note',
        name:'Person_Note',
        component: person_note
      },
      {
        path: '/Personal/Person_Idle',
        name:'Person_Idle',
        component: person_idle
      },
      {
        path: '/Personal/One_Note',
        component: one_note
      },
      {
        path: '/Personal/One_Mypost',
        component: one_mypost
      },
      {
        path: '/Personal/One_Myidle',
        component: one_myidle
      },

    ]
  },
  {
    path: '/Personal_Info',
    name:'Personal_Info',
    component: person_info,
    children: [
      {
        path: '/Personal_Info/Person_Basic',
        name:'Person_Basic',
        component: person_basic
      },
      {
        path: '/Personal_Info/Person_Identity',
        name:'Person_Identity',
        component: person_identity
      },
      {
        path: '/Personal_Info/Person_Account',
        name:'Person_Account',
        component: person_account
      },
    ]
  },
  //  闲置转卖
  {
    path: '/Resale',
    name: 'Resale',
    component: Resale,
    children: [
      {
        path: '/Resale/All_Resale',
        component: all_resale
      },
    ]
  },
  //  积分中心
  {
    path: '/Score',
    name: 'Score',
    component: Score
  },
  //  登录注册
  {
    path: '/Gegister',
    name: 'Gegister',
    component: Gegister

  },
    //其他用户个人中心
  {
    path: '/User_Main',
    name:'User_Main',
    component: user_main,
    children: [
      {
        path:'/User_Main/User_Note',
        name:'User_Note',
        component: user_note
      },
      {
        path:'/User_Main/User_Post',
        name:'User_Post',
        component: user_post
      },
      {
        path:'/User_Main/User_Idle',
        name:'User_Idle',
        component: user_idle
      },
      {
        path:'/User_Main/User_One_Note',
        name:'User_One_Note',
        component: user_one_note
      },




    ]
  }

]

const router = new VueRouter({
  routes
})

// 前端路由守卫判断是否登录
router.beforeEach((to,from,next)=>{

  if(to.path==='/Gegister')
  {
    next();
  }
  else if(to.path==='/'){

    next();

  }
  else if(to.path === '/KaoYan_Frame/Information'){
    next();
  }
  else if(to.path === '/KaoYan_Frame/KaoYan_Info'){
    next();
  }
  else if(to.path === '/KaoYan_Frame/ZhaoShen_Info'){
    next();
  }
  else if(to.path === '/KaoYan_Frame/Daily_Info'){
    next();
  }
  else if(to.path === '/KaoYan_Frame/Recommend_Info'){
    next();
  }
  else if(to.path === '/KaoYan_Frame/Other_Info'){
    next();
  }
  else if(to.path === '/KaoYan_Frame/One_Info'){
    next();
  }
  else
  {
    //如果token不存在，用户未登录
     if(!window.sessionStorage.getItem('token') || window.sessionStorage.getItem('token')==null || window.sessionStorage.getItem('token')===''|| window.sessionStorage.getItem('token')===undefined)
     {
       next('/Gegister');
       // this.$message.warning("请先登录，方可访问！");

     }else{
       next();
     }
  }
  // 防止重复点击导航栏:个人中心
  // if((from.path==='/Personal/Person_Note'))
  // {
  //   next(from.path);
  // }







})

export default router
